package bean;

import hibernate.PublicationRepository;

import java.io.Serializable;
import java.util.Date;

import javax.faces.bean.ManagedBean;

import metier.MessagePriveBusiness;
import metier.PublicationBusiness;
@ManagedBean
public class PublicationBean implements Serializable {

	private static final long serialVersionUID = 1L;
	private int id_message;
	private String contenu;
	private Date date_envoie;
	private int id_eleve_destinataire;
	private int id_eleve_emetteur;
	private PublicationBusiness publicationCourant;
	private PublicationRepository publicationRepo;
	private boolean privacy;

	public PublicationBean() {
		super();
		publicationCourant = new PublicationBusiness();
		publicationRepo = new PublicationRepository();
	}

	public int getId_message() {
		return id_message;
	}
	public void setId_message(int id_message) {
		this.id_message = id_message;
	}
	public String getContenu() {
		return contenu;
	}
	public void setContenu(String contenu) {
		this.contenu = contenu;
	}
	public Date getDate_envoie() {
		return date_envoie;
	}
	public void setDate_envoie(Date date_envoie) {
		this.date_envoie = date_envoie;
	}
	public int getId_eleve_destinataire() {
		return id_eleve_destinataire;
	}
	public void setId_eleve_destinataire(int id_eleve_destinataire) {
		this.id_eleve_destinataire = id_eleve_destinataire;
	}
	public int getId_eleve_emetteur() {
		return id_eleve_emetteur;
	}
	public void setId_eleve_emetteur(int id_eleve_emetteur) {
		this.id_eleve_emetteur = id_eleve_emetteur;
	}
	public PublicationBusiness getPublicationCourant() {
		return publicationCourant;
	}
	public void setPublicationCourant(PublicationBusiness publicationCourant) {
		this.publicationCourant = publicationCourant;
	}
	public boolean isPrivacy() {
		return privacy;
	}
	public void setPrivacy(boolean privacy) {
		this.privacy = privacy;
	}
	public String ajoutMessage() {

		System.out.println("NOUVELLE PUBLICATION");

		if(publicationCourant != null){
			System.out.println("PUBLICATION OK");
			if(contenu != "")
				publicationCourant.save(this);
			else
				System.out.println("CONTENU VIDE");
		}
		setContenu("");
		return "AjoutMessageOK";

	}

	public String delete(){

		if(publicationCourant != null){
			PublicationBean pub = publicationRepo.GetById(id_message);
			publicationCourant.Delete(pub);
			return "supprOK";
		}

		return "supprKO";
	}

}
